package main

import (
	"fmt"
	"sync"

	"gitee.com/technology-to-share/concurrency-of-shared-variables/example1/bank"
)

func main() {
	for i := 0; i < 100000; i++ {
		test1()
	}
}

func test1() {
	bank.Init()
	var wg sync.WaitGroup
	wg.Add(2)
	// A:
	go func() {
		bank.Add(200)                    // A1
		fmt.Println("=", bank.Balance()) // A2

		wg.Done()
	}()

	// B:
	go func() {
		bank.Add(100) // B
		wg.Done()

	}()
	wg.Wait()
}
